package com.example.task1.ui.AllService.parking;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.ParkingCartBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class ParkingCartActivity extends BaseActivity {

    private RecyclerView rvList;
    private Button btnSave;
    private ParkingCartAdapter parkingCartAdapter;

    @Override
    protected void onRestart() {
        super.onRestart();
        initData();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_parking_cart);
        initView();
        initData();
        parkingCartAdapter = new ParkingCartAdapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rvList.setLayoutManager(linearLayoutManager);
        rvList.setAdapter(parkingCartAdapter);
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(ParkingCartActivity.this, ParkingModificationCartActivity.class, 1);
            }
        });
    }

    private void initData() {
        Call<ApiResp> call = Api.api().get(MyApplication.TOKEN, "/prod-api/api/park/car/my");
        Api.send(call, ParkingCartBean.class, new CallBack<ParkingCartBean>() {
            @Override
            public void success(ParkingCartBean data) {
                parkingCartAdapter.setData(data.getRows());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    @Override
    public String getMyTitle() {
        return "我的车辆信息";
    }

    private void initView() {
        rvList = findViewById(R.id.rv_list);
        btnSave = findViewById(R.id.btn_save);
    }
}